package com.tct.worktimeboard.controller;

import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.JSONPObject;
import com.tct.worktimeboard.feishu.FeiShuService;
import com.tct.worktimeboard.mapper.UserInfoMapper;
import com.tct.worktimeboard.util.JsonUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * @author Huhailong
 * @Description
 * @Date 2021/5/26.
 */
@RestController
@RequestMapping("/feishu")
public class FeiShuController {

    @Autowired
    FeiShuService feiShuService;

    @PostMapping("/sendMessage")
    public JSONObject sendMessage(@RequestBody Map<String,String> data, HttpServletRequest request){
        String userId = request.getHeader("userId");
        if(data.get("sendType")==null||data.get("sendType").isEmpty()){
            return JsonUtil.toErrorData("请选择发送类型后发送");
        }
        if("1".equals(userId)){
            String sendType = data.get("sendType");
            String message = data.get("message");
            return feiShuService.sendMessage(Integer.parseInt(sendType),message);
        }
        return JsonUtil.toErrorData("您没有权限发送消息！");
    }

    @PostMapping("getFeiShuMessage")
    public JSONObject getFeiShuMessage(@RequestBody Map<String,Object> data){
        System.out.println(JSONObject.toJSONString(data));
        return null;
    }
}
